package master

import (
	"io/ioutil"
	"encoding/json"
)

var (
	G_config *Config
)

type Config struct {
	ApiPort         int      `json:"apiPort"`
	ApiReadTimeout  int      `json:"apiReadTimeout"`
	ApiWriteTimeout int      `json:"apiWriteTimeout"`
	EtcdEndPoints   []string `json:"etcdEndpoints"`
	EtcdDialTimeout int      `json:"etcdDialTimeout"`
}

//加载配置
func InitConfig(filename string) (err error) {
	var (
		content []byte
		conf    Config
	)
	//1.读取配置
	if content, err = ioutil.ReadFile(filename); err != nil {
		return
	}
	//2.反序列化JSON
	if err = json.Unmarshal(content, &conf); err != nil {
		return
	}
	//3.赋值单例
	G_config = &conf

	return
}
